package com.owc.controller.app;

import com.owc.domain.BaseResult;
import com.owc.domain.dto.Authority;
import com.owc.domain.dto.PayPwd;
import com.owc.domain.dto.UserInfo;
import com.owc.domain.vo.app.LoginVo;
import com.owc.domain.vo.app.ModifyVo;
import com.owc.domain.vo.app.RegisterVo;
import com.owc.service.app.PermissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @Author xiaom
 * @Date 2019/12/2 11:24
 * @Version 1.0.0
 * @Description <Permission router control >
 **/
@RestController
@RequestMapping("/auth")
@Api(tags = "(APP-V1)权限相关")
public class AuthController {

    private final PermissionService permissionService;

    public AuthController(PermissionService permissionService) {
        this.permissionService = permissionService;
    }

    /**
     * User register.
     */
    @PostMapping(value = "/register")
    @ApiOperation("注册")
    public BaseResult<Authority> register(@RequestBody @Valid RegisterVo registerVo) {
        return BaseResult.success(permissionService.register(registerVo));
    }

    /**
     * User login.
     * @return JWT Token.
     */
    @PostMapping(value = "/login")
    @ApiOperation("登录")
    public BaseResult<Authority> login(@RequestBody @Valid LoginVo loginVo){
        return BaseResult.success(permissionService.login(loginVo));
    }

    /**
     * Fetch current login user base info.
     */
    @PostMapping(value = "/getUserInfo")
    @ApiOperation("获取用户基本信息")
    public BaseResult<UserInfo> getUserInfo(){
        return BaseResult.success(permissionService.getUserInfo());
    }

    /**
     * Modify user password.
     */
    @PostMapping(value = "/modifyPwd")
    @ApiOperation("修改密码")
    public BaseResult<Boolean> modifyPwd(@RequestBody ModifyVo modifyVo){
        return BaseResult.success(permissionService.modifyPassword(modifyVo));
    }

    /**
     * Check pay password is setting.
     */
    @PostMapping(value = "/checkIsSetPayPwd")
    @ApiOperation("检查是否设置支付密码")
    public BaseResult<PayPwd> checkIsSetPayPwd(){
        return BaseResult.success(permissionService.checkIsSetPayPwd());
    }
}
